package com.jianyun.jyzs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.jianyun.jyzs.R;
import com.jianyun.jyzs.adapter.RightStateAdapter;
import com.jianyun.jyzs.bean.CrmFunnelList;
import com.jianyun.jyzs.constant.SysConstant;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.utils.LoginCache;
import com.jianyun.jyzs.utils.UtilsStyle;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/6/4.
 * 漏斗状态  客户状态
 */

public class CrmGetFunnelActivity extends AppCompatActivity {
    @BindView(R.id.topBack)
    ImageView topBack;
    @BindView(R.id.topText)
    TextView topText;
    @BindView(R.id.tv_checked)
    TextView tvChecked;
    @BindView(R.id.tv_update)
    TextView tvUpdate;
    @BindView(R.id.iv_more)
    ImageView ivMore;
    @BindView(R.id.iv_moreLinearLayout)
    LinearLayout ivMoreLinearLayout;
    @BindView(R.id.topCreat)
    LinearLayout topCreat;
    @BindView(R.id.iv_single)
    ImageView ivSingle;
    @BindView(R.id.iv_group)
    ImageView ivGroup;
    @BindView(R.id.topChatDetail)
    LinearLayout topChatDetail;
    @BindView(R.id.topId)
    RelativeLayout topId;
    @BindView(R.id.loadButton)
    Button loadButton;
    @BindView(R.id.nullLinearLayout)
    LinearLayout nullLinearLayout;
    @BindView(R.id.noticeList)
    ListView listView;
    private RightStateAdapter adapter;
    private String enterpriseCode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        UtilsStyle.setStatusBarMode(this,true);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        topBack.setVisibility(View.VISIBLE);
        topBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        topText.setText("选择漏斗状态");
        enterpriseCode = LoginCache.getInstance().getLoginCache().getEnterpriseCode();
        adapter = new RightStateAdapter(this, null);
        listView.setAdapter(adapter);
        getFunnel();
    }

    private void getFunnel() {
        try {
            Api api = RetrofitHelper.builderErpRoot().create(Api.class);
            api.getNewSomeFunnel("crm_ldjd", enterpriseCode,"jyzs","Android","1.0.2")
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new CustomCallback<CrmFunnelList>() {
                        @Override
                        protected void onResponse(CrmFunnelList response) {
                            if (response.isResult()) {
                                List<CrmFunnelList.FunnelBean> list = response.getData();
                                adapter.setData(list);
                            }
                        }

                        @Override
                        protected void onException(String msg) {

                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public void setFunnel(String name) {
        Intent intent = new Intent();
        intent.putExtra(SysConstant.msg_key_string1, name);
        setResult(RESULT_OK, intent);
        finish();
    }
}
